package visualization;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Paint;
import java.awt.Stroke;

import javax.swing.JFrame;
import javax.swing.JPanel;

import org.apache.commons.collections15.Transformer;

import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.util.EdgeType;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		OligoGraph<String, String> g2 = new OligoGraph<String, String>();
		g2.addVertex("1");
		g2.addVertex("2");
		g2.addVertex("3");
		g2.addVertex("11");
		g2.addVertex("22");
		g2.addVertex("33");
		g2.addEdge("1->1", "1", "1", EdgeType.DIRECTED);
		g2.addEdge("2->2", "2", "2", EdgeType.DIRECTED);
		g2.addEdge("3->3", "3", "3", EdgeType.DIRECTED);
		g2.addInhibition("Inh11", "11", "1->1");
		g2.addInhibition("Inh22", "22", "2->2");
		g2.addInhibition("Inh33 ", "33", "3->3");
		g2.addEdge("1->Inh22", "1", "22", EdgeType.DIRECTED);
		g2.addEdge("2->Inh33", "2", "33", EdgeType.DIRECTED);
		g2.addEdge("3->Inh11", "3", "11", EdgeType.DIRECTED);
		
		Layout<String, String> layout = new CircleLayout(g2);
		layout.setSize(new Dimension(250, 250));
		VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(
				layout);
		vv.setPreferredSize(new Dimension(300, 300));
		// Setup up a new vertex to paint transformer...
		Transformer<String, Paint> vertexPaint = new Transformer<String, Paint>() {
			public Paint transform(String i) {
				return Color.GREEN;
			}
		};
		// Set up a new stroke Transformer for the edges
		/*
		 * float dash[] = { 10.0f }; final Stroke edgeStroke = new
		 * BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
		 * 10.0f, dash, 0.0f);
		 */
		final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
				BasicStroke.JOIN_MITER, 10.0f);
		Transformer<String, Stroke> edgeStrokeTransformer = new Transformer<String, Stroke>() {
			public Stroke transform(String s) {
				return edgeStroke;
			}
		};

		vv.setRenderer(new OligoRenderer());
		vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
		//vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
		// vv.getRenderContext().setEdgeArrowTransformer(new
		// edu.uci.ics.jung.visualization.decorators.Picka)
		
		vv.getRenderContext().setEdgeArrowTransformer(
				new PA2EdgeArrowTransformer<String, String>());
		vv.getRenderContext().setVertexLabelTransformer(
				new MyVertexLebeller<String>());
		// vv.getRenderContext().setEdgeLabelTransformer(new
		// ToStringLabeller());
		vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
		DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
		gm.setMode(ModalGraphMouse.Mode.PICKING);
		vv.setGraphMouse(gm);
		JFrame frame = new JFrame();
		JPanel newPanel = new JPanel();
		frame.add(newPanel);
		newPanel.add(vv);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(1500, 600);
		frame.show();
	}

}
